﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using BCL.BaseLib;
using System.Reflection;
using BCL.BaseLib.Basics;
namespace BCL.Component
{
    public partial class ImageButton : DevExpress.XtraEditors.XtraUserControl
    {
        public ImageButton()
        {
            InitializeComponent();
            SetButton(btnMain);
            
        }
        /// <summary>
        /// 按钮图片
        /// </summary>
        public Image image
        {
            get { return this.btnMain.BackgroundImage = image; }
            set
            {
                this.btnMain.BackgroundImage = value;
            }
        }

        /// <summary>
        /// 按钮标题文本
        /// </summary>
        public string Title
        {
            get { return this.lblTitle.Text; }
            set
            {
                this.toolTip.SetTitle(this, value);
                this.lblTitle.Text = value;
            }
        }


        //定义委托
        public delegate void Btn_Click(FunctionEntity fe);
        //定义事件
        public event Btn_Click BtnClicked;

        private void ButtonItem_Click(object sender, EventArgs e)
        {
           // BCLApplication.MainForm.App_Click();
            if (BtnClicked != null)
            {
                BtnClicked(this.Tag as FunctionEntity);//把按钮自身作为参数传递
            }

        }

        private void SetButton(Button button)
        {
            System.Reflection.MethodInfo methodinfo = button.GetType().GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod);
            methodinfo.Invoke(button, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, new object[] { ControlStyles.Selectable, false }, Application.CurrentCulture);
        }

    }

}
